package com.boot.mgt.controller.web

import com.boot.core.result.ResultTo
import com.boot.mgt.controller.web.vo.TaPoliceVo
import com.boot.mgt.service.TaOndutyAccidentService
import com.boot.mgt.service.TaOndutyMobileService
import com.boot.mgt.service.TaPoliceService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.format.annotation.DateTimeFormat
import org.springframework.web.bind.annotation.*
import java.util.*

/**
 * 警员管理接口
 * @author rankai
 * createTime 2018-01-2018/1/9 11:09
 */
@RestController
@RequestMapping("/admin/police")
class TaPoliceController {

    @Autowired
    private lateinit var policeService: TaPoliceService

    /**
     * 警员列表
     * modified by liuzhe @2019-01-16 修正未处理page_size参数问题
     */
    @GetMapping("/list")
    fun list(type: Int?, police_number: String?, name: String?, page_index: Int?, page_size:Int?,  is_all: Boolean?): ResultTo {
        return policeService.list(type, police_number, name, page_index ?: 1, page_size?:20,  is_all ?: false)
    }

    /**
     * 根据ID获取警员信息
     */
    @GetMapping("/getById")
    fun getPoliceById(id: String): ResultTo {
        return policeService.getPoliceById(id)
    }

    /**
     * 编辑警员信息包含新增
     */
    @PostMapping("/edit")
    fun edit(@RequestBody policeVo: TaPoliceVo): ResultTo {
        return policeService.edit(policeVo)
    }

    /**
     * 编辑警员信息包含新增
     */
    @PostMapping("/editRpc")
    fun editRpc(@RequestBody policeVo: TaPoliceVo, police_level: Int, police_id: String, org_num: String): ResultTo {
        return policeService.editRpc(policeVo, police_level, police_id, org_num)
    }

    /**
     * 编辑警员信息包含新增
     */
    @PostMapping("/edit_no_old_password")
    fun editNoOldPassword(@RequestBody policeVo: TaPoliceVo): ResultTo {
        return policeService.editNoOldPassword(policeVo)
    }

    /**
     * 查看排班
     */
    @GetMapping("/selectScheduling")
    fun selectScheduling(@RequestParam(required = false, defaultValue = "1") type: Int?,
                         police_number: String?,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") start_time: Date?,
                         @DateTimeFormat(pattern = "yyyy-MM-dd") end_time: Date?): ResultTo {
        return policeService.selectScheduling(type, police_number, start_time, end_time)
    }

    /**
     * 排班
     */
    @PostMapping("/scheduling")
    fun scheduling(police_number: String, date: String): ResultTo {
        return policeService.scheduling(police_number, date)
    }


}